<?php
class Form_Sistema extends Zend_Form
{
	public function __construct($options = null)
	{
		parent::__construct($options);
		$this->setName('sistema_form');

		$id = new Zend_Form_Element_Hidden('id');
		$nome_sistema = new Zend_Form_Element_Text('nome_sistema');
		$nome_sistema->setLabel("Nome do Sistema")->setAttrib('size','50')
		    ->setRequired('true')
		    ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty');
        $nome_servidor = new Zend_Form_Element_Text('nome_servidor');
        $nome_servidor->setLabel("Nome/IP do Servidor")->setAttrib('size','50')
            ->setRequired('true')
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty');            
        $nome_banco = new Zend_Form_Element_Text('nome_banco');
        $nome_banco->setLabel("Nome do banco de dados")->setAttrib('size','50')
            ->setRequired('true')
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty');            
 
        $nome_usuario = new Zend_Form_Element_Text('nome_usuario');
        $nome_usuario->setLabel("Usuário padrão")->setAttrib('size','50')
            ->setRequired('true')
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty');                          
            
        
        $servertype_id  = $this->getServerTypes();    
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel("Salvar");    
        
        $this->addElements(array($id,$nome_sistema, $nome_servidor,$nome_banco, $nome_usuario, $servertype_id,$submit));
		
	}
    public function getServerTypes() {

        
        $servertypes = new Model_Servertypes();
        
        $formServerTypes = new Zend_Form_Element_Select('servertype_id');
        foreach($servertypes->fetchAll() as $g) 
            $formServerTypes->addMultiOption($g->id ,$g->servertype);
        $formServerTypes->setLabel ( "Tipo de servidor:" )
            ->setRequired ( true );
        return $formServerTypes;
    }	
    public function getDados()
    {
        $return = $this->getValues();
        unset($return['submit']);
        unset($return['id']);
        foreach ($return as $k=>$v)
        {
            if(is_array($v))
            unset($return[$k]);
        }
        return $return;
    }
}